/*
type int
parse 5 5
parse 5 2+3
parse 6 '2 *' 3
parse 919512 '456 +' '123 *' '(' 543 + 7 '*' '(' 987 + 2 ')' + 6 ')'
noparse 1:1 Sum x
end '456 +'
*/

# Bryan Ford's trivial grammar with integers, spacing, repetitions, and
# character classes.

Sum :: int ← _ a:Additive → a
Additive ← m:Multitive $ Plus $ a:Additive { m + a } / m:Multitive -> m
Multitive ← p:Primary $ Times $ m:Multitive { p * m } / p:Primary -> p
Primary ← Left $ a:Additive $ Right -> a / d:Decimal -> d
Decimal ← [0-9]+ _ { atoi(ref_ptr(ref())) }

Left :: void ← "(" _
Right ← ")" _
Plus ← "+" _
Times ← "*" _
_ ← [ \t\n] *
